package lightswitch.server.code.sqlhelper.statement.select;

import java.util.ArrayList;
import java.util.List;


import lightswitch.server.code.util.StringHelper;

public class OrderBy {

	List<OrderByItem> _orderItemList;
	public OrderBy()
	{
		
	}
	public OrderBy(String statement,From _from)
	{
		if(statement=="")
		{
			_orderItemList = new ArrayList<>();
			return;
		}
		statement = StringHelper.NormalizeString(statement);
		_orderItemList = new ArrayList<>();
		statement = statement.substring("orderby ".length()); 
		statement = StringHelper.NormalizeString(statement);
		String[] items = statement.split(",");
		for(int i=0;i<items.length;i++)
		{
			
			OrderByItem item  = new OrderByItem(items[i],_from);
			_orderItemList.add(item); 
		}
		
	}
	public String toString()
	{
		String t =" order by ";
		t= t + " ";
		for(int i=0;i<_orderItemList.size();i++)
		{
			t = t +_orderItemList.get(i).column.toString() + " "+_orderItemList.get(i).orderType  + " , " ;
		}
		return t+ "  ";
	}
}
